package com.atguigu.srb.core.controller.admin;

import com.atguigu.srb.common.result.R;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.entity.UserLoginRecord;
import com.atguigu.srb.core.pojo.query.UserInfoQuery;
import com.atguigu.srb.core.service.UserInfoService;
import com.atguigu.srb.core.service.UserLoginRecordService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/core/userInfo")
@Api("后台管理会员管理接口")
@Slf4j
//@CrossOrigin
public class AdminUserInfoController {
    @Autowired
    UserInfoService userInfoService;
    @Autowired
    UserLoginRecordService userLoginRecordService;
    @ApiOperation("查询用户列表")
    @GetMapping("list/{page}/{limit}")
    public R list(@PathVariable Long page, @PathVariable Long limit, UserInfoQuery userInfoQuery){
        Page<UserInfo> pageModel = new Page(page,limit);
        pageModel = userInfoService.listPage(pageModel,userInfoQuery);
        return R.ok().data("pageModel",pageModel);
    }

    @ApiOperation("查询用户列表锁")
    @PutMapping("lock/{id}/{status}")
    public R lock(@PathVariable Long id, @PathVariable Integer status){
        userInfoService.lock(id,status);
        return R.ok();
    }
    @ApiOperation("查询用户登录日志列表")
    @GetMapping("getuserLoginRecordTop50/{id}")
    public R getuserLoginRecordTop50(@PathVariable Long id){
        List<UserLoginRecord> userLoginRecordList = userLoginRecordService.getuserLoginRecordTop50(id);
        return R.ok().data("list",userLoginRecordList);
    }
}
